import java.util.*;
public class Main {
    public static void main(String[] args)

    {
       //测试
       String s="{[]}";
       System.out.println(isValid(s));
    }

     static boolean isValid(String s)
     {
         LinkedStack<Character> stack=new LinkedStack<>();
         char[] chars=s.toCharArray();
         for(char c:chars)
         {
             if(c=='['||c=='{'||c=='(')
                 stack.push(c);
             else{
                 if(stack.isEmpty())
                     return false;
                 Character ch=stack.pop();
                 if(c==')'&&ch!='(')return false;
                 if(c==']'&&ch!='[')return false;
                 if(c=='}'&&ch!='{')return false;

             }
         }
         return stack.isEmpty();
     }
}

